home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / scrnsvrs / scrnsavr.lzh / Faze.S < prev    next >
Text File  |  1992-05-12  |  17KB  |  546 lines

  1. *-------------------------------------*
  2. *    -F-A-Z-E- Screen Saver          *
  3. *      by Damien M. Jones          *
  4. *         Version 1.00          *
  5. *-------------------------------------*
  6.  
  7. *    This screen saver is built around a generic screen saver
  8. *    frame.  The frame hooks into the VBL and KBD/MIDI interrupts,
  9. *    displays a successful installation message, and then terminates
  10. *    with ptermres.
  11. *
  12. *    I've gone through (May 12, 1992) and added extra comments to
  13. *    clear up some confusion.  The separate parts of the program
  14. *    have been more clearly labeled.  If you don't like the way
  15. *    I format my assembly, tough; I write it for me, not for you.
  16.  
  17. *    Code begins.
  18.  
  19. *    Generic Screen Saver
  20. *    by Damien M. Jones
  21. *    Copyright 1992 Damien M. Jones, All Rights Reserved.
  22. *
  23. *    Just change the "saver" routine to change the screen saver.
  24. *    Please include a note in your documentation that you used
  25. *    the "Generic Screen Saver Frame by dmj"; I place no other
  26. *    restrictions on the use of this code.  So you could release
  27. *    a Shareware screen saver using this code, and you wouldn't
  28. *    have to send me a penny.  A copy of the screensaver would
  29. *    be nice, but not mandatory.
  30.  
  31. *    If you leave the "id" string as it is, you can use the BoinkCfg
  32. *    program to set the time delay for the screen saver, as well
  33. *    as disable it.  Otherwise, you'll have to write your own
  34. *    config program.
  35.  
  36. *    You'll need to change the amount of memory to save, around line
  37. *    182.  Faze uses a 32K screen, plus space for the program.
  38.  
  39.     jmp install        ; Install program.
  40.  
  41. *    Variables (for the config program).
  42.  
  43. id    dc.b 'dmjScreenSaver'    ; Fourteen-byte ID string.
  44. ssave    dc.w 0            ; Old screen address.
  45. screen    dc.w 0            ; Address of screen saver screen.
  46. timeout    dc.w 300        ; Default is two minutes.
  47. count    dc.w 300        ; Number of cycles left to wait.
  48. flag    dc.w 0            ; Set if screen saver active.
  49. palsave    dc.w 0,0,0,0,0,0,0,0    ; Place to store system palette.
  50.     dc.w 0,0,0,0,0,0,0,0
  51. rezsave    dc.w 0            ; Place to store system resolution.
  52. pal    dc.w $000,$722,$631,$540,$450,$361,$272,$163 ; Screensaver palette.
  53.     dc.w $054,$045,$136,$227,$316,$405,$504,$613
  54. rez    dc.w 0            ; Resolution of screen saver.
  55. rndseed    dc.l $31415926        ; Random number generator seed.
  56.  
  57. *    The VBL.  Decrements timer, then checks to see if screen saver
  58. *    needs to be activated.  It then jumps to the OS VBL.
  59.  
  60. vbl    tst.w flag        ; Is the screen saver active?
  61.     beq vskip        ; No, need to check counter.
  62.  
  63.     jsr saver        ; Call the screen save subroutine.
  64.     bra jmp1        ; All done.
  65.  
  66. vskip    move.l a0,-(a7)        ; Save this register.
  67.     move.l #count,a0    ; Address of count variable.
  68.  
  69.     subq.w #1,(a0)        ; Decrement counter.
  70.     tst.w (a0)+        ; Is it zero?
  71.     bne vblend        ; Nope, exit now.
  72.  
  73.     st (a0)            ; Set in-use flag.
  74.     movem.l d0/a1,-(a7)    ; Save these register too.
  75.     lea $FFFF8240.w,a1    ; Address of palette registers.
  76.     move.l #palsave,a0    ; Address to save into.
  77.  
  78.     move.l (a1)+,(a0)+    ; Save palette.
  79.     move.l (a1)+,(a0)+
  80.     move.l (a1)+,(a0)+
  81.     move.l (a1)+,(a0)+
  82.     move.l (a1)+,(a0)+
  83.     move.l (a1)+,(a0)+
  84.     move.l (a1)+,(a0)+
  85.     move.l (a1)+,(a0)+
  86.     move.w (a1)+,(a0)+    ; Resolution.
  87.  
  88.     lea $FFFF8240.w,a1    ; Address of palette registers.
  89.  
  90.     move.l (a0)+,(a1)+    ; Move in saver palette.
  91.     move.l (a0)+,(a1)+
  92.     move.l (a0)+,(a1)+
  93.     move.l (a0)+,(a1)+
  94.     move.l (a0)+,(a1)+
  95.     move.l (a0)+,(a1)+
  96.     move.l (a0)+,(a1)+
  97.     move.l (a0)+,(a1)+
  98.     move.b (a0),(a1)    ; And saver resolution.
  99.  
  100.     lea $FFFF8201.w,a1    ; Screen address vars in Shifter.
  101.     move.l #ssave,a0    ; Address of variable.
  102.     movep.w 0(a1),d0    ; Read old value.
  103.     move.w d0,(a0)+        ; And save it.
  104.     move.w (a0),d0        ; Get saver screen address.
  105.     movep.w d0,0(a1)    ; Copy over address.
  106.  
  107.     movem.l (a7)+,d0/a1    ; Restore registers.
  108.  
  109. vblend    move.l (a7)+,a0        ; Restore register.
  110. jmp1    jmp $11111111        ; Jump to old VBL.
  111.  
  112. *    The keyboard interrupt.  Resets VBL timer, and shuts off screen
  113. *    saver if it's active.
  114.  
  115. kbd    move.l a0,-(a7)        ; Save this register.
  116.  
  117.     move.l #timeout,a0    ; Address of variable.
  118.     move.w (a0)+,(a0)+    ; Copy over word.
  119.  
  120.     tst.w (a0)+        ; Was the screen saver active?
  121.     beq kbdend        ; No, exit now.
  122.  
  123.     movem.l d0/a1,-(a7)    ; Save these registers too.
  124.     lea $FFFF8240.w,a1    ; Address of palette registers.
  125.  
  126.     move.l (a0)+,(a1)+    ; Restore palette.
  127.     move.l (a0)+,(a1)+
  128.     move.l (a0)+,(a1)+
  129.     move.l (a0)+,(a1)+
  130.     move.l (a0)+,(a1)+
  131.     move.l (a0)+,(a1)+
  132.     move.l (a0)+,(a1)+
  133.     move.l (a0)+,(a1)+
  134.     move.b (a0),(a1)    ; Restore resolution.
  135.  
  136.     lea $FFFF8201.w,a1    ; Screen address vars in Shifter.
  137.     move.l #ssave,a0    ; Address of variable.
  138.     move.w (a0),d0        ; Get contents.
  139.     movep.w d0,0(a1)    ; Copy over address.
  140.  
  141.     clr.w flag        ; Clear this flag.
  142.     movem.l (a7)+,d0/a1    ; Restore these registers.
  143.  
  144. kbdend    move.l (a7)+,a0        ; Restore register.
  145. jmp2    jmp $11111111        ; Jump to old KBD.
  146.  
  147. *    The installation routine.  Displays install message, hooks into
  148. *    KBD/MIDI and VBL, and exits with ptermres.
  149.  
  150. install    pea initmsg        ; Address of text.
  151.     move.w #9,-(a7)        ; cconws
  152.     trap #1            ; GEMDOS(9)
  153.     addq.l #6,a7        ; Adjust stack.
  154.  
  155.     move.w #4,-(a7)        ; getrez
  156.     trap #14        ; XBIOS(4)
  157.     addq.l #2,a7        ; Adjust stack.
  158.  
  159.     cmp.b #2,d0        ; High resolution?
  160.     bne color        ; No, install and exit.
  161.  
  162.     pea errmsg        ; Address of text.
  163.     move.w #9,-(a7)        ; cconws
  164.     trap #1            ; GEMDOS(9)
  165.     addq.l #6,a7        ; Adjust stack.
  166.  
  167.     clr.w -(a7)        ; pterm0
  168.     trap #1            ; GEMDOS(0) - No return.
  169.  
  170. color    pea init        ; Address of init routine.
  171.     move.w #38,-(a7)    ; supexec
  172.     trap #14        ; XBIOS(38)
  173.     addq.l #6,-(a7)        ; Adjust stack.
  174.  
  175.     bsr sinit        ; Init Screen Saver.
  176.  
  177.     pea okmsg        ; Address of text.
  178.     move.w #9,-(a7)        ; cconws
  179.     trap #1            ; GEMDOS(9)
  180.     addq.l #6,a7        ; Adjust stack.
  181.  
  182.     move.l #34080,-(a7)    ; Save 33K for program & screen.
  183.     move.w #49,-(a7)    ; ptermres
  184.     trap #1            ; GEMDOS(49) - No return.
  185.  
  186. *    This actually hooks the interrupts.
  187.  
  188. init    movem.l d0/a0,-(a7)    ; Save this register.
  189.     move.w sr,-(a7)        ; Save status register.
  190.     move.w #$2700,sr    ; No interruptions.
  191.  
  192.     move.l #jmp2+2,a0    ; Address of jump instruction.
  193.     move.l $118.w,(a0)    ; Copy over old keyboard vector.
  194.     move.l #kbd,a0        ; Address of KBD routine.
  195.     move.l a0,$118.w    ; Store it.
  196.  
  197.     move.l #jmp1+2,a0    ; Address of jump instruction.
  198.     move.l $70.w,(a0)    ; Copy over old VBL vector.
  199.     move.l #vbl,a0        ; Address of VBL routine.
  200.     move.l a0,$70.w        ; Store it.
  201.  
  202.     move.l #svscrn,d0    ; Address of screen area.
  203.     add.l #255,d0        ; Round up if necessary.
  204.     lsr.l #8,d0        ; Shift that address down.
  205.     move.w d0,screen    ; Save screen address.
  206.  
  207.     move.w (a7)+,sr        ; Restore status register.
  208.     movem.l (a7)+,d0/a0    ; Restore this register.
  209.     rts            ; Return.
  210.  
  211. *    Init custom to FAZE.  Different screen savers will require
  212. *    different init code here.
  213.  
  214. sinit    clr.l d0        ; Make sure all of this is clear.
  215.     move.w screen,d0    ; Get screen address.
  216.     lsl.l #8,d0        ; Shift it to get real address.
  217.     move.l d0,a0        ; Copy to address register.
  218.  
  219.     move.w #7679,d1        ; Number of words.
  220.     move.l #-1,d2        ; Word to move.
  221.  
  222. siloop    move.l d2,(a0)+        ; Store word.
  223.     dbra d1,siloop        ; Next long.
  224.  
  225.     rts            ; All done.
  226.  
  227. *    The actual saver routine; it makes the screen saver what it is.
  228. *    This routine, the one above it, and the amount of memory to
  229. *    save on line 182 are all you need to change to make a different
  230. *    screen saver.
  231.  
  232. *    -F-A-Z-E- Screen Save Routine
  233. *    by Damien M. Jones
  234. *    Copyright 1992 Damien M. Jones, All Rights Reserved.
  235.  
  236. *    Basically, this program picks a random point from 0,0 to 31,31.
  237. *    It then checks the adjacent four points.  If any of these are
  238. *    in the next lower color, nothing is done.  Otherwise, if two
  239. *    of the connecting points are of the next higher color, then
  240. *    the point is plotted in that next higher color.  Otherwise it
  241. *    has a 20% chance of being plotted in that next higher color.
  242. *    Colors wrap, so 1 is the next higher color after 15.
  243.  
  244. *    Only one point is tested per VBL.  This routine takes about
  245. *    11% of processor time.
  246.  
  247. saver    movem.l d0-d7/a0-a2,-(a7) ; Save registers.
  248.  
  249.     bsr rnd            ; Randomize.
  250.  
  251.     clr.l d0        ; Make sure all of this is clear.
  252.     move.w screen,d0    ; Get screen address.
  253.     lsl.l #8,d0        ; Shift it to get real address.
  254.     move.l d0,a0        ; Copy to address register.
  255.  
  256. Faze    bsr rnd            ; Get